const jwt=require('jsonwebtoken')

const whiteList=['/login']

const auth=(option,app)=>{
    return async(ctx,next)=>{
        if(whiteList.includes(ctx.path)){
            await next()
        }else{
            let token=ctx.request.header.token
            if(token){
                console.log(token)
                try{
                    jwt.verify(token,'1906A')
                    await next()
                }catch(err){
                    ctx.body={
                        code:302,
                        mes:'token验证失败'
                    }
                }
            }else{
                ctx.body={
                    code:304,
                    mes:'无token'
                }
            }
        }
    }
}

module.exports=auth